package com.golden.common;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.UUID;

import com.golden.common.model.MenuModel;
import com.golden.user.model.UserModel;

public class CommonUtil {

	public static final DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
	
	public static boolean isBlankOrEmpty(String str){
		return str == null || str.trim().length() == 0 ? true : false;
	}
	
	public static boolean isBlankOrEmpty(List<?> list){
		return list == null || list.size() == 0 ? true : false;
	}
	
	public static boolean isBlankOrEmpty(String[] str){
		return str == null || str.length == 0 ? true : false;
	}
	
	
	public static UserModel createGuestUser(){
		UserModel userModel = new UserModel();
		userModel.setRoleId(CommonNames.GUEST_ID);
		return userModel;
	}
	
	public static String getCurrentMenuNameByMenuId(String menuId, List<MenuModel> list){
		for(MenuModel menu : list){
			if(menuId.equals(menu.getMenuId())){
				return menu.getMenuName();
			}
		}
		return "";
	}
	
	public static String getCurrentDateString(){
		Date date = new Date();
		return df.format(date);
	}
	
	public static boolean isInArray(String[] array, String str){
		for(String temp : array){
			if(str.startsWith(temp))
				return true;
		}
		return false;
	}
	
	public static String reImageName(String fileName) {
		String name = UUID.randomUUID().toString();
		int index = fileName.lastIndexOf(".");
		String type = fileName.substring(index);
		return name + type;
	}
	
	public static String generaterKey(){
		String uuid = UUID.randomUUID().toString();
		String time = System.nanoTime() + uuid.substring(0,5);
		if(time.length() > 20){
			return time.substring(time.length() - 20);
		}else{
			return time;
		}
	}
	
}


